package com.wfcm.utils;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;

import java.util.Properties;

public class ConstantUtil {
    public static String APP_ID = "";//王芳课堂appId 微信开发平台appId
    public static String APP_SECRET = "";//王芳课堂app_SECRET app对应的密钥
    public static String PARTNER = "";//爱看爱秀账户 财付通商户号
    public static String APP_KEY = "";//(APP_KEY和PARTNER_KEY一样) 应用对应的凭证
    public static String PARTNER_KEY = "";//爱看爱秀商户秘钥 商户号对应的密钥，自设API秘钥
    public static String GG_PARTNER_KEY = "";//爱看爱秀商户秘钥(测试-正式一样) 商户号对应的密钥，自设API秘钥

    public static String GG_APP_ID = "";//微信开发平台appId
    public static String GG_APP_SECRET = "";//app对应的密钥
    public static String GG_PARTNER = "";//财付通商户号
    public static String GG_APP_KEY = "";//应用对应的凭证 -- (APP_KEY和PARTNER_KEY一样)
    public static String WX_API_PROJECT = "";//公共号商户平台 -- 微信公众平台的接口系统
    public static String WX_PROJECT = "";// 微信公众平台系统

    public static String environment = ""; // tset测试环境  product正式环境

    public static String SMALL_APPID = "";//好芳法课堂小程序appId
    public static String SMALL_SECRET = "";// 好芳法课堂小程序对应的密钥

    public static String TOKENURL = "https://api.weixin.qq.com/cgi-bin/token";// 获取access_token对应的url
    public static String GRANT_TYPE = "client_credential";// 常量固定值
    public static String EXPIRE_ERRCODE = "42001";// access_token失效后请求返回的errcode
    public static String FAIL_ERRCODE = "40001";// 重复获取导致上一次获取的access_token失效,返回错误码
    public static String GATEURL = "https://api.weixin.qq.com/pay/genprepay?access_token=";// 获取预支付id的接口url
    public static String ACCESS_TOKEN = "access_token";// access_token常量值
    public static String ERRORCODE = "errcode";// 用来判断access_token是否失效的值
    public static String SIGN_METHOD = "sha1";// 签名算法常量值

    //获取预支付id的接口url
    public static String ORDER = "https://api.mch.weixin.qq.com/pay/unifiedorder";// 签名算法常量值
    // package常量值
    public static String packageValue = "bank_type=WX&body=%B2%E2%CA%D4&fee_type=1&input_charset=GBK&notify_url=http%3A%2F%2F127.0.0.1%3A8180%2Ftenpay_api_b2c%2FpayNotifyUrl.jsp&out_trade_no=2051571832&partner=1900000109&sign=10DA99BCB3F63EF23E4981B331B0A3EF&spbill_create_ip=127.0.0.1&time_expire=20131222091010&total_fee=1";
    public static String traceid = "testtraceid001";// 测试用户id
    
    /*#苹果支付沙箱验证地址 :https://sandbox.itunes.apple.com/verifyReceipt  
    #苹果支付正式验证地址:https://buy.itunes.apple.com/verifyReceipt 
     */
    //验证苹果支付是否成功
    public static String iosTest = "https://sandbox.itunes.apple.com/verifyReceipt";
    public static String iosPay = "https://buy.itunes.apple.com/verifyReceipt";

    // 使用静态代码块读取properties文件
    static {

        try {
            Resource resource = new ClassPathResource("/db.properties");
            Properties db = PropertiesLoaderUtils.loadProperties(resource);

            APP_ID = (String) db.get("APP_ID");
            APP_SECRET = (String) db.get("APP_SECRET");
            PARTNER = (String) db.get("PARTNER");
            APP_KEY = (String) db.get("APP_KEY");
            PARTNER_KEY = (String) db.get("PARTNER_KEY");
            GG_PARTNER_KEY = (String) db.get("GG_PARTNER_KEY");

            GG_APP_ID = (String) db.get("GG_APP_ID");
            GG_APP_SECRET = (String)db.get("GG_APP_SECRET");
            GG_PARTNER = (String)db.get("GG_PARTNER");
            GG_APP_KEY = (String)db.get("GG_APP_KEY");
            WX_API_PROJECT = (String)db.get("WX_API_PROJECT");
            WX_PROJECT = (String)db.get("WX_PROJECT");

            SMALL_APPID = (String)db.get("SMALL_APPID");
            SMALL_SECRET = (String)db.get("SMALL_SECRET");

            environment =  (String)db.get("environment");

        } catch (Exception e) {
            // TODO: handle exception
        }

    }
}
